package main

import "fmt"

//演示二维数组
func main() {
	//方式1
	arr := [2][3]int32{{1, 2, 3}, {4, 5, 6}}
	fmt.Println(arr)

	//方式2
	var arr2 [2][3]int32
	arr2[0][0] = 10
	arr2[0][1] = 11
	arr2[0][2] = 12

	arr2[1][0] = 20
	arr2[1][1] = 21
	arr2[1][2] = 22
	fmt.Println(arr2)

	//方式3：外层一维数组长度用...
	arr3 := [...][2]int32{{1, 2}, {3, 4}}
	fmt.Println(arr3)

	//二维数组的遍历
	//for循环
	for i := 0; i < len(arr3); i++ {
		fmt.Printf("第%v层\n", i)
		for j := 0; j < len(arr3[i]); j++ {
			fmt.Printf("%v \t", arr3[i][j])
		}
		fmt.Println()
	}

	//for-range
	for i, v := range arr3 {
		fmt.Printf("第%v层 \n", i)
		for _, innerV := range v {
			fmt.Printf("%v \t", innerV)
		}
		fmt.Println()
	}

}
